package com.eims.sls_app.utils;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.eims.sls_app.dataaccess.Lottery;
import com.eims.sls_app.fragment.HallFragment;
import com.eims.sls_app.ui.AmountOfCharge;
import com.eims.sls_app.ui.Buy_DLT_Activit;
import com.eims.sls_app.ui.Buy_RX9_Activit;
import com.eims.sls_app.ui.Buy_SFC_Activity;
import com.eims.sls_app.ui.SelectNumberActivity;
import com.eims.sls_app.ui.SelectNumberActivityFC3D;
import com.eims.sls_app.ui.SelectNumberActivityPL3;
import com.eims.sls_app.ui.SelectNumberActivityPL5_QXC;
import com.eims.sls_app.ui.Select_11X5Activity;
import com.eims.sls_app.ui.Select_JXSSCActivity;
import com.eims.sls_app.ui.Select_QlcActivity;
import com.eims.sls_app.ui.Select_SSCActivity;
import com.eims.sls_app.ui.Select_k3Activity;
import com.eims.sls_app.view.ConfirmDialog;
import com.eims.sls_app.view.MyToast;
import com.umeng.socialize.utils.Log;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import bls.juejin.cn.R;

/**
 * 通用方法类
 */
public class LotteryUtils {
	/**
	 * 格式化时间
	 * 
	 */
	private static final String TAG = "FileUtils";

	public static String Long2DateStr_detail(long time) {
		String format = "yyyy-M-d HH:mm";
		Date date = new Date(time);
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		String long_time = sdf.format(date);
		return long_time;
	}

	/**
	 * 根据日期推出具体星期
	 * 
	 * @return
	 */
	public static String getWeekOfDate(String dt) throws Exception {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Date date = format.parse(dt);
		String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	/**
	 * 根据日期推出具体星期
	 * 
	 * @return
	 */
	public static String getTeamWeekOfDate(String dt) throws Exception {

		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		Date date = format.parse(dt);
		String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;

		if (w < 0)
			w = 0;
		return weekDays[w];
	}
	/**
	 * 根据日期推出具体星期
	 * 
	 * @return
	 */
	public static int getBetweenOfDate(String dt) throws Exception {

		Timestamp endtime=new Timestamp(System.currentTimeMillis());
		
		long lcc_time = Long.valueOf(dt);
		Timestamp Starttime=new Timestamp(new Date(lcc_time * 1000L).getTime());
		int minSum=(int) ((endtime.getTime() - Starttime.getTime())/(1000*60));
		
		return minSum;
	}
	// 将时间戳转为字符串
	public static String getStrTimebytimestamp(String cc_time) {
		String re_StrTime = null;
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

		long lcc_time = Long.valueOf(cc_time);
		re_StrTime = sdf.format(new Date(lcc_time * 1000L));
		return re_StrTime;
	}

	/**
	 * 获取现在时间
	 * 
	 * @return 返回短时间字符串格式yyyy-MM-dd
	 */
	public static String getStringDateShort() {
		//
		long time = System.currentTimeMillis();
		final Calendar mCalendar = Calendar.getInstance();
		mCalendar.setTimeInMillis(time);

		int apm = mCalendar.get(Calendar.AM_PM);
		Date dNow = new Date(); // 当前时间
		Date dBefore = new Date();

		Calendar calendar = Calendar.getInstance(); // 得到日历
		calendar.setTime(dNow);// 把当前时间赋给日历
		calendar.add(Calendar.DAY_OF_MONTH, -1); // 设置为前一天
		dBefore = calendar.getTime(); // 得到前一天的时间
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		//
		if (apm == 0) {

			String dateString = formatter.format(dBefore);
			return dateString;
		} else {

			String dateString = formatter.format(dNow);
			return dateString;
		}

	}

	/**
	 * 根据日期推出具体星期
	 * 
	 * @return
	 */
	public static String getWeekOfDatebyDate(String dt) throws Exception {
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
		Date date = format.parse(dt);
		String[] weekDays = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" };
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
		if (w < 0)
			w = 0;
		return weekDays[w];
	}

	/**
	 * @param -根据LotteryId得彩种名称
	 * @return
	 */
	public static String getTitleText(String LotteryId) {
		String lotteryNameString = "";
		if ("6".equals(LotteryId)) {
			lotteryNameString = "3D";
		} else if ("5".equals(LotteryId)) {
			lotteryNameString = "双色球";
		} else if ("63".equals(LotteryId)) {
			lotteryNameString = "排列三";
		} else if ("78".equals(LotteryId)) {
			lotteryNameString = "广东11选5";
		} else if ("64".equals(LotteryId)) {
			lotteryNameString = "排列五";
		} else if ("3".equals(LotteryId)) {
			lotteryNameString = "七星彩";
		} else if ("39".equals(LotteryId)) {
			lotteryNameString = "大乐透";
		} else if ("13".equals(LotteryId)) {
			lotteryNameString = "七乐彩";
		} else if ("74".equals(LotteryId)) {
			lotteryNameString = "胜负彩";
		} else if ("75".equals(LotteryId)) {
			lotteryNameString = "任九场";
		} else if ("62".equals(LotteryId)) {
			lotteryNameString = "十一运夺金";
		} else if ("82".equals(LotteryId)) {
			lotteryNameString = "幸运彩";
		} else if ("28".equals(LotteryId)) {
			lotteryNameString = "重庆时时彩";
		} else if ("70".equals(LotteryId)) {
			lotteryNameString = "江西11选5";
		} else if ("83".equals(LotteryId)) {
			lotteryNameString = "江苏快3";
		} else if ("72".equals(LotteryId)) {
			lotteryNameString = "竞彩足球";
		} else if ("73".equals(LotteryId)) {
			lotteryNameString = "竞彩篮球";
		} else if ("45".equals(LotteryId)) {
			lotteryNameString = "北京单场";
		} else if ("61".equals(LotteryId)) {
			lotteryNameString = "江西时时彩";
		}
		return lotteryNameString;
	}

	/**
	 * 充值提示框
	 */
	public static void showMoneyLess(final Context context, final long totalMoney) {
		ConfirmDialog dialog = new ConfirmDialog(context, R.style.dialog);
		dialog.show();
		dialog.setDialogContent(context.getResources().getString(R.string.recharge));
		dialog.setDialogResultListener(new ConfirmDialog.DialogResultListener() {
			@Override
			public void getResult(int resultCode) {
				if (1 == resultCode) {// 确定
					/*
					 * Intent intent = new Intent(context, RechargeActivity.class);
					 * intent.putExtra("money", Double.valueOf(totalMoney));
					 * context.startActivity(intent);
					 */
					Intent intent_alipay = new Intent();
					Bundle bundle_alipay = new Bundle();
					intent_alipay.setClass(context, AmountOfCharge.class);
					bundle_alipay.putInt("Type", 1);
					intent_alipay.putExtras(bundle_alipay);
					context.startActivity(intent_alipay);

					// Intent intent = new Intent();
					// intent.setClass(context, PayWebActivity.class);
					// context.startActivity(intent);
				}
			}
		});
	}

	/**
	 * 三个月以内的消息
	 * 
	 * @param list
	 * @return
	 */
	public static boolean checkThreeMonth(List<String> list) {
		try {
			if (list != null && list.size() != 0) {
				int topYear = Integer.valueOf(list.get(0).split("-")[0]);
				int topMonth = Integer.valueOf(list.get(0).split("-")[1]);

				int lowYear = Integer.valueOf(list.get(list.size() - 1).split("-")[0]);
				int lowMonth = Integer.valueOf(list.get(list.size() - 1).split("-")[1]);
				if (topYear - lowYear > 1) {
					return false;
				} else if (topYear - lowYear == 1) {
					// 三个月以内
					if ((topMonth + 12) - lowMonth < 3) {
						return true;
					}
				} else {
					if ((topMonth - lowMonth) < 3) {
						return true;
					}
				}
			}
		} catch (Exception e) {
			System.out.println("checkThreeMonth  :" + e.toString());
		}
		return false;
	}

	/**
	 * 比较时间，相差三个月返回true
	 * 
	 * @param date
	 * @param date1
	 * @return
	 */
	public static boolean compareMonth(String date, String date1) {
		try {
			if (!TextUtils.isEmpty(date) && date.contains("-") && !TextUtils.isEmpty(date1) && date1.contains("-")) {
				int topYear = Integer.valueOf(date.split("-")[0]);
				int topMonth = Integer.valueOf(date.split("-")[1]);

				int lowYear = Integer.valueOf(date1.split("-")[0]);
				int lowMonth = Integer.valueOf(date1.split("-")[1]);

				if (topYear - lowYear > 1) {
					return false;
				} else if (topYear - lowYear == 1) {
					// 三个月以内
					if ((topMonth + 12) - lowMonth < 3) {
						return true;
					}
				} else {
					if ((topMonth - lowMonth) < 3) {
						return true;
					}
				}
			}
		} catch (Exception e) {
			System.out.println("checkThreeMonth  :" + e.toString());
		}
		return false;
	}

	/**
	 * 拼接订单编号
	 * 
	 * @param lotteryId
	 * @param isuseName
	 * @param schemeids
	 * @return
	 */
	public static String getSchemeNum(String lotteryId, String isuseName, int schemeids) {
		String schemeNumMiddle = "";
		if ("6".equals(lotteryId)) {
			// lotteryNameString = "3D";
			schemeNumMiddle = "3D";
		} else if ("63".equals(lotteryId)) {
			// lotteryNameString = "排列三";
			schemeNumMiddle = "PL3";
		} else if ("5".equals(lotteryId)) {
			// lotteryNameString = "双色球";
			schemeNumMiddle = "SSQ";
		} else if ("62".equals(lotteryId)) {
			// lotteryNameString = "山东11选5";
			schemeNumMiddle = "";
		} else if ("64".equals(lotteryId)) {
			// lotteryNameString = "排列五";
			schemeNumMiddle = "PL5";
		} else if ("3".equals(lotteryId)) {
			// lotteryNameString = "七星彩";
			schemeNumMiddle = "QXC";
		} else if ("39".equals(lotteryId)) {
			// lotteryNameString = "大乐透";
			schemeNumMiddle = "TCCJDLT";
		} else if ("13".equals(lotteryId)) {
			// lotteryNameString = "七乐彩";
			schemeNumMiddle = "QLC";
		} else if ("74".equals(lotteryId)) {
			// lotteryNameString = "胜负彩";
			schemeNumMiddle = "SFC";
		} else if ("75".equals(lotteryId)) {
			// lotteryNameString = "任九场";
			schemeNumMiddle = "RJC";
		} else if ("82".equals(lotteryId)) {
			// lotteryNameString = "幸运彩";
			schemeNumMiddle = "XYC";
		} else if ("28".equals(lotteryId)) {
			// lotteryNameString = "时时彩";
			schemeNumMiddle = "CQSSC";
		} else if ("61".equals(lotteryId)) {
			// lotteryNameString = "江西时时彩";
			schemeNumMiddle = "JXSSC";
		} else if ("70".equals(lotteryId)) {
			// lotteryNameString = "11选5";
			schemeNumMiddle = "JX11X5";
		} else if ("83".equals(lotteryId)) {
			// lotteryNameString = "江苏快3";
			schemeNumMiddle = "JSK3";
		} else if ("72".equals(lotteryId)) {
			// lotteryNameString = "竞彩足球";
			schemeNumMiddle = "JCZQ";
		} else if ("73".equals(lotteryId)) {
			// lotteryNameString = "竞彩篮球";
			schemeNumMiddle = "JCLQ";
		}
		return isuseName + schemeNumMiddle + schemeids;
	}

	/**
	 * 返回当前的"yyyy-MM-dd"
	 * 
	 * @param now
	 * @return
	 */
	public static String getSchemeTime(long now) {
		String time;
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		time = dateFormat.format(new Date(now));
		return time;
	}

	/**
	 * 将玩法id转换成玩法名称
	 * 
	 * @return
	 */

	public static String transPlayName(String playID, String LotteryNum) {
		String str = null;
		String name = LotteryHelp.getNameByID(playID, LotteryNum);
		if (name != null)
			return name;
		try {
			switch (Integer.valueOf(playID)) {
			// 江西时时彩的直选。。
			case 61031:
				str = "一星直选";
				break;
			case 61032:
				str = "二星直选";
				break;
			case 61033:
				str = "三星直选";
				break;
			case 61034:
				str = "四星直选";
				break;
			case 61035:
				str = "五星直选";
				break;

			// 大乐透
			case 3901:
				str = "普通投注";
				break;
			case 3902:
				str = "普通追加投注";
				break;
			case 3903:
				str = "胆拖投注";
				break;
			case 3904:
				str = "胆拖追加投注";
				break;
			case 3906:
				str = "后区胆拖";
				break;
			case 3908:
				str = "后区胆拖追加投注";
				break;
			case 3907:
				str = "双区胆拖";
				break;
			case 3909:
				str = "双区胆拖追加投注";
				break;

			// 双色球
			case 501:
				str = "普通投注";
				break;
			case 502:
				str = "胆拖投注";
				break;

			// 3D
			case 601:
				str = "普通投注";
				break;
			case 602:
				str = "组三";
				break;
			case 603:
				str = "组六";
				break;
			case 604:
				str = "1D";
				break;
			case 605:
				str = "猜1D";
				break;
			case 606:
				str = "2D";
				break;
			case 607:
				str = "猜2D两同号";
				break;
			case 608:
				str = "猜2D两不同";
				break;
			case 609:
				str = "通选";
				break;
			case 610:
				str = "和数";
				break;
			case 611:
				str = "包选三";
				break;
			case 612:
				str = "包选六";
				break;
			case 613:
				str = "猜大小";
				break;
			case 614:
				str = "猜三同";
				break;
			case 615:
				str = "拖拉机";
				break;
			case 616:
				str = "猜奇偶";
				break;
			// 胜负彩
			case 7401:
				// 任选九
			case 7501:
				str = "普通投注";
				break;
			// 排列3
			case 6301:
				str = "普通投注";
				break;
			case 6302:
				str = "组六单式";
				break;
			case 6303:
				str = "组选六复式";
				break;
			case 6304:
				str = "组选三复式";
				break;
			case 6305:
				str = "直选和值";
				break;
			case 6306:
				str = "组选和值";
				break;
			// 排列5
			case 6401:
				str = "普通投注";
				break;
			// 七乐彩
			case 1301:
				str = "普通投注";
				break;
			// 七星彩
			case 301:
				str = "普通投注";
				break;
			// 重庆时时彩
			case 2803:
				int index = LotteryNum.trim().replace(" ", "").lastIndexOf("-");
				if (index == 3) {
					str = "一星直选";
				} else if (index == 2) {
					str = "二星直选";
				} else if (index == 1) {
					str = "三星直选";
				} else if (index == -1) {
					str = "五星直选";
				}
				break;
			case 2804:
				str = "大小单双";
				break;
			case 2805:
				str = "五星通选";
				break;
			case 2806:
				str = "二星组选";
				break;
			case 2811:
				str = "三星组三";
				break;
			case 2812:
				str = "三星组六";
				break;
			case 2814:
				str = "组三包胆";
				break;
			case 2815:
				str = "组三和值";
				break;

			// 江西11选5/广东11选5/山东11选5
			case 7001:
			case 7801:
			case 6201:
				str = "前一";
				break;
			case 7002:
			case 7802:
			case 6202:
				str = "任选二";
				break;
			case 7003:
			case 7803:
			case 6203:
				str = "任选三";
				break;
			case 7004:
			case 7804:
			case 6204:
				str = "任选四";
				break;
			case 7005:
			case 7805:
			case 6205:
				str = "任选五";
				break;
			case 7006:
			case 7806:
			case 6206:
				str = "任选六";
				break;
			case 7007:
			case 7807:
			case 6207:
				str = "任选七";
				break;
			case 7008:
			case 7808:
			case 6208:
				str = "任选八";
				break;
			case 7009:
			case 7809:
			case 6209:
				str = "前二直选";
				break;
			case 7010:
			case 7810:
			case 6210:
				str = "前三直选";
				break;
			case 7011:
			case 7811:
			case 6211:
				str = "前二组选";
				break;
			case 7012:
			case 7812:
			case 6212:
				str = "前三组选";
				break;
			case 7013:
			case 7813:
			case 6213:
				str = "前二胆拖";
				break;
			case 7014:
			case 7814:
			case 6214:
				str = "前三胆拖";
				break;
			case 7015:
			case 7815:
			case 6215:
				str = "任选二胆拖";
				break;
			case 7016:
			case 7816:
			case 6216:
				str = "任选三胆拖";
				break;
			case 7017:
			case 7817:
			case 6217:
				str = "任选四胆拖";
				break;
			case 7018:
			case 7818:
			case 6218:
				str = "任选五胆拖";
				break;
			case 7019:
			case 7819:
			case 6219:
				str = "任选六胆拖";
				break;
			case 7020:
			case 7820:
			case 6220:
				str = "任选六胆拖";
				break;

			// 江苏快三
			case 8301:
				str = "和值";
				break;
			case 8302:
				str = "三同号通选";
				break;
			case 8303:
				str = "三同号单选";
				break;
			case 8304:
				str = "二同号复选";
				break;
			case 8305:
				str = "二同号单选";
				break;
			case 8306:
				str = "三不同号";
				break;
			case 8307:
				str = "二不同号";
				break;
			case 8308:
				str = "三连号通选";
				break;
			default:
				break;
			}
		} catch (NumberFormatException e) {
			return "普通投注";
		}
		return str;
	}

	/**
	 * 正则匹配电话号码
	 */
	public static boolean checkPhoneREX(String value) {

		String regExp = "1[0-9]{10}";
		// String regExp = "^((13[0-9])|(15[^4,\\D])|(18[0-9]))\\d{8}$";
		// String regExp = "^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(value);
		return m.find();
	}

	public static String convertSchemeState(int Share, int BuyedShare, boolean buyed, int quashStatus, boolean isopened,
			double winmoney) {
		String SchemeState = "";
		if (Share > BuyedShare && !buyed) {
			SchemeState = "招募中";
		} else if (Share <= BuyedShare && !buyed && !isopened) {
			SchemeState = "待出票";
		} else if (Share <= BuyedShare && buyed && !isopened) {
			SchemeState = "已出票";
		} else if (Share <= BuyedShare && !buyed && isopened) {
			SchemeState = "已流单";
		} else if (Share <= BuyedShare && buyed && isopened && winmoney == 0) {
			SchemeState = "未中奖";
		} else if (Share <= BuyedShare && buyed && isopened && winmoney > 0) {
			SchemeState = "已中奖";
		}
		if (quashStatus > 0) {
			SchemeState = "已撤单";
		}
		return SchemeState;
	}

	private static final String BOUNDARY = "----WebKitFormBoundaryT1HoybnYeFOGFlBR";

	/**
	 * 
	 * @param params
	 *            传递的普通参数
	 * @param uploadFile
	 *            需要上传的文件名
	 * @param fileFormName
	 *            需要上传文件表单中的名字
	 * @param newFileName
	 *            上传的文件名称，不填写将为uploadFile的名称
	 * @param urlStr
	 *            上传的服务器的路径
	 * @throws IOException
	 */
	public static void uploadForm(Map<String, String> params, String fileFormName, File uploadFile, String newFileName,
			String urlStr) throws IOException {
		if (newFileName == null || newFileName.trim().equals("")) {
			newFileName = uploadFile.getName();
		}

		StringBuilder sb = new StringBuilder();
		/**
		 * 普通的表单数据
		 */
		for (String key : params.keySet()) {
			sb.append("--" + BOUNDARY + "\r\n");
			sb.append("Content-Disposition: form-data; name=\"" + key + "\"" + "\r\n");
			sb.append("\r\n");
			sb.append(params.get(key) + "\r\n");
		}
		/**
		 * 上传文件的头
		 */
		sb.append("--" + BOUNDARY + "\r\n");
		sb.append("Content-Disposition: form-data; name=\"" + fileFormName + "\"; filename=\"" + newFileName + "\""
				+ "\r\n");
		sb.append("Content-Type: text/plain" + "\r\n");// 如果服务器端有文件类型的校验，必须明确指定ContentType
		sb.append("\r\n");

		byte[] headerInfo = sb.toString().getBytes("UTF-8");
		byte[] endInfo = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("UTF-8");
		// System.out.println(sb.toString());
		URL url = new URL(urlStr);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
		conn.setRequestProperty("Content-Length",
				String.valueOf(headerInfo.length + uploadFile.length() + endInfo.length));
		conn.setDoOutput(true);

		OutputStream out = conn.getOutputStream();
		InputStream in = new FileInputStream(uploadFile);
		out.write(headerInfo);

		byte[] buf = new byte[1024];
		int len;
		while ((len = in.read(buf)) != -1)
			out.write(buf, 0, len);

		out.write(endInfo);
		in.close();
		out.close();
		if (conn.getResponseCode() == 200) {
			InputStream in1 = new BufferedInputStream(conn.getInputStream());
			String result = readInStream(in1);
			System.out.println(result);
			uploadFile.delete();
		}
	}

	private static String readInStream(InputStream in) {
		Scanner scanner = new Scanner(in).useDelimiter("\\A");
		return scanner.hasNext() ? scanner.next() : "";
	}

	/**
	 * 根据彩种id跳转不同选号页面
	 * 
	 * @param lotteryID
	 *            彩种id
	 */
	public static void goToSelectLottery(Context context, String lotteryID) {
		int id = Integer.parseInt(lotteryID);
		Intent intent = null;
		Lottery mLottery = AppTools.getLotteryById(lotteryID);
		if (mLottery != null) {
			App.lottery = mLottery;
		} else {
			MyToast.getToast(context, "该奖期已结束，请等下一期").show();
			return;
		}
		switch (id) {
		case 5:// 双色球
			intent = new Intent(context, SelectNumberActivity.class);
			break;
		case 39:// 大乐透
			intent = new Intent(context, Buy_DLT_Activit.class);
			break;
		case 6:// 3D
			intent = new Intent(context, SelectNumberActivityFC3D.class);
			break;
		case 63:// 排列三
			intent = new Intent(context, SelectNumberActivityPL3.class);
			break;
		case 64:// 排列五
			intent = new Intent(context, SelectNumberActivityPL5_QXC.class);
			break;
		case 75:// 任选九
			intent = new Intent(context, Buy_RX9_Activit.class);
			break;
		case 74:// 胜负彩
			intent = new Intent(context, Buy_SFC_Activity.class);
			break;
		case 3:// 七星彩
			intent = new Intent(context, SelectNumberActivityPL5_QXC.class);
			break;
		case 13:// 七乐彩
			intent = new Intent(context, Select_QlcActivity.class);
			break;
		case 62:// 十一运夺金
		case 70:
		case 78:// 11选5
			intent = new Intent(context, Select_11X5Activity.class);
			break;
		case 28:// 时时彩
			intent = new Intent(context, Select_SSCActivity.class);
			break;
		case 61:// 江西时时彩
			intent = new Intent(context, Select_JXSSCActivity.class);
			break;
		case 83:// 江苏快3
			intent = new Intent(context, Select_k3Activity.class);
			break;
		}
		context.startActivity(intent);
	}

	/**
	 * 根据彩种id跳转不同选号页面
	 * 
	 * @param lotteryID
	 *            彩种id
	 */
	public static void goToSelectLottery_jc(Context context, String lotteryID) {
		Lottery mLottery = AppTools.getLotteryById(lotteryID);
		if (mLottery == null) {
			MyToast.getToast(context, "该奖期已结束，请等下一期").show();
			return;
		}
		App.lottery = mLottery;
		HallFragment.refreType = true;
		if (App.lottery.getDtmatch() != null && App.lottery.getDtmatch().length() != 0) {
			if (lotteryID.equals("72")) {// 竞彩足球
				new HallFragment().getBallData(context, 0);
			} else if (lotteryID.equals("73")) {// 竞彩篮球
				new HallFragment().getBasketball(context, 0);
			} else if (lotteryID.equals("45")) {// 竞彩篮球
				new HallFragment().getBjdcData(context);
			}
		} else {
			MyToast.getToast(context, "没有对阵信息").show();
		}
	}

	public static String decrypt3DES(String input, String key) {
		return decrypt3DES(input, key, Charset.forName("GB2312"));
	}

	public static String decrypt3DES(String input, String key, Charset charset) {
		try {
			return new String(Des.decrypt(Byte.hex2byte(input.getBytes()), key.getBytes()), charset.name());
		} catch (Exception localException) {
		}
		return "";
	}

	public static String encrypt3DES(String input, String key) {
		return encrypt3DES(input, key, Charset.forName("GB2312"));
	}

	public static String encrypt3DES(String input, String key, Charset charset) {
		try {
			return Byte.byte2hex(Des.encrypt(input.getBytes(charset.name()), key.getBytes()));
		} catch (Exception localException) {
		}
		return "";
	}

	public static String getRexQue(String str) {
		Pattern p = Pattern.compile("\\(.*?\\)");// 查找规则公式中大括号以内的字符
		Matcher m = p.matcher(str);
		String param = null;
		while (m.find()) {// 遍历找到的所有大括号
			param = m.group().replaceAll("\\(\\)", "");// 去掉括号
		}
		return param;
	}

	/**
	 * 获得“-”分割的数组
	 * 
	 * @param str
	 * @return
	 */
	public static String[] getRexArray(String str) {
		if (!str.contains("-"))
			return new String[] { str, "" };
		else {
			String str_pre = str.substring(0, str.lastIndexOf("-"));
			String str_suffix = str.substring(str.lastIndexOf("-") + 1, str.length());
			return new String[] { str_pre, str_suffix };
		}
	}

	public static int[] getScreenWidthAndHeight(Context context) {
		WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics dm = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(dm);
		int screenWidth = dm.widthPixels;
		int screenHeigh = dm.heightPixels;
		return new int[] { screenWidth, screenHeigh };
	}

	/**
	 * 将中奖轮播中的人名信息加密***
	 */
	public static String addRexStarMarquee(String target) {
		Pattern pattern = Pattern.compile("[A-Za-z0-9\\u4e00-\\u9fa5]{3,16}\\s[\\u4e00-\\u9fa5]{2}");
		Matcher matcher = pattern.matcher(target);
		StringBuffer sbr = new StringBuffer();
		while (matcher.find()) {
			String find = matcher.group();
			find = addRexStar(find.substring(0, find.indexOf(" ")));
			if (find != null)
				matcher.appendReplacement(sbr, find + " 喜中");
		}
		matcher.appendTail(sbr);
		System.out.println(sbr.toString());
		return sbr.toString();
	}

	/**
	 * 对人名（自己除外）已***加密
	 */
	public static String addRexStar(String name) {
		if (TextUtils.isEmpty(name))
			return null;
		if (App.user != null && name.equals(App.user.getName())) {
			return name;
		} else {
			// return name.substring(0, 2) + "***";
			// //版本修改，此处不做加密处理，直接取后台的返回数据.隐藏该条数据
			return name;
		}
	}

	/**
	 * 判断字符长度
	 */
	public static int getRexStrLength(String target) {
		int charLength = 0;
		String chinese = "^[\\u4e00-\\u9fa5]+$";
		String num_enchar = "^\\w+$";
		Pattern pattern_chinese = Pattern.compile(chinese);
		Pattern pattern_num_enchar = Pattern.compile(num_enchar);
		for (String str : target.split("")) {
			if (!"".equals(str)) {
				if (pattern_chinese.matcher(str).matches()) {
					charLength += 2;
				} else if (pattern_num_enchar.matcher(str).matches()) {
					charLength += 1;
				}
			}
		}
		return charLength;
	}
}
